package com.mustafaiev.tair.mweather;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

import com.mustafaiev.tair.mweather.exception.MWeatherParseException;
import com.mustafaiev.tair.mweather.forecast.Town;
import com.mustafaiev.tair.mweather.xml.MWeatherXMLParser;

public class TownAutocompleteActivity extends Activity implements TextWatcher {

	AutoCompleteTextView autoCompleteTextView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.main_activity_layout);

		MWeatherXMLParser parser = new MWeatherXMLParser();
		ArrayList<Town> towns = null;
		try {
			towns = parser.getParsedTowns(this.getAssets());
		} catch (MWeatherParseException e) {
			Log.e("TownAutocompleteActivity, method onCreate()", e.toString());
		}

		this.autoCompleteTextView = (AutoCompleteTextView) this
				.findViewById(R.id.town_autocomplete);
		this.autoCompleteTextView.addTextChangedListener(this);

		if (towns != null) {
			this.autoCompleteTextView.setAdapter(new ArrayAdapter<Town>(this,
					R.id.town_item, towns));
		}
	}

	public void afterTextChanged(Editable s) {
		
	}

	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {

	}

	public void onTextChanged(CharSequence s, int start, int before, int count) {

	}
}
